﻿Shader "Dan/UI/UI_RadialGrid"
{
    Properties
    {
        _Color ("Color", Color) = (0.07843138,0.3921569,0.7843137,1)
        _Emission ("Emission", Float ) = 1
        _Grid_u ("Grid_u", Float ) = 32
        _Grid_v ("Grid_v", Float ) = 8
        _Width ("Width", Range(0, 1)) = 0.1
        _Speed ("Speed", Float ) = 1

    }
    
    SubShader
    {

        Tags { "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent" }
        LOD 100    
        Blend SrcAlpha OneMinusSrcAlpha
        ZWrite Off 
 
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "UnityCG.cginc"
            #include "../ShaderLibs/UIFX.cginc"
            #include "../ShaderLibs/UVOperator.cginc"
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };
            
            struct v2f
            {
                float4 vertex : SV_POSITION;    
                float2 uv : TEXCOORD0;
                
            };

             float4 _Color;
             float _Grid_v;
             float _Speed;
             float _Width;
             float _Grid_u;
             float _Emission;

            v2f vert ( appdata v )
            {
                
                v2f o;
                UNITY_INITIALIZE_OUTPUT(v2f ,o);
                o.vertex = UnityObjectToClipPos(v.vertex);
                
                o.uv = v.uv;        
                return o;
            }
            
            


            fixed4 frag (v2f i ) : SV_Target
            {
                float2 uv = i.uv;
                float3 finalColor = _Color.rgb*_Emission;
                 
                float2 ruv = uv*2-1;
                float shape = max(abs(ruv.x),abs(ruv.y));
                float polar = DrawPolar(ruv);
                float gridWidth_U =step(frac((polar*_Grid_u)),_Width);
                float gridWidth_V =step(frac((shape*_Grid_v)-(_Time.y*_Speed)),_Width);
                
                float grid = gridWidth_U+gridWidth_V;
                shape =shape*shape*(1 - shape)*8;

                return fixed4(finalColor,grid*shape);
                
                
            }
            ENDCG
        }
    }
    
    
    
}
